<template>
<div class="merchant-settlement views-container">
    <el-dialog :visible.sync="dialogVisibleImg" width="30%" @close="clearData" custom-class="reset-pwd wlm-form-dialog dialog-table">
        <div class="wlm-form" v-if="dialogVisibleImg">
            <div class="wlm-form-header wlm-dialog-fixheader">
                <span class="wlm-dialog-inlenr">标记</span>
            </div>
            <el-scrollbar wrap-class="scrollbar-wrapper">
                <div class="wlm-form-content">
                    <div class="wlm-dialog-main">
                        <div class="wlm-dialog-content">
                            <el-form ref="userForm" :model="moniForm" size="small" label-width="120px" class="retail-form" label-position="right">
                                <el-form-item label="标记">
                                    <el-radio-group v-model="historyColor">
                                        <el-radio label="red">
                                            <svg-icon icon-class="qisan" class="qi-svg red" />
                                        </el-radio>
                                        <el-radio label="yellow">
                                            <svg-icon icon-class="qisan" class="qi-svg yellow" />
                                        </el-radio>
                                        <el-radio label="green">
                                            <svg-icon icon-class="qisan" class="qi-svg green" />
                                        </el-radio>
                                        <el-radio label="blue">
                                            <svg-icon icon-class="qisan" class="qi-svg blue" />
                                        </el-radio>
                                        <el-radio label="purple">
                                            <svg-icon icon-class="qisan" class="qi-svg purple" />
                                        </el-radio>
                                    </el-radio-group>
                                </el-form-item>
                                <el-form-item label="标记信息">
                                    <el-input type="textarea" :autosize="{ minRows: 4, maxRows: 4}" v-model="historyRemark">
                                    </el-input>
                                </el-form-item>
                            </el-form>
                        </div>
                    </div>
                </div>
            </el-scrollbar>
        </div>
        <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
            <el-button size="small"  @click="dialogVisibleImg=false">关闭</el-button>
            <el-button size="small" type="primary" @click="saveDialog">确定</el-button>
        </footer>
    </el-dialog>
    <div class="wlm-table">
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="80px" class="retail-form" label-position="right">
                <el-form-item label="商家名称：" class="search">
                    <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.name" placeholder="请输入商家名称" style="width:160px;"></el-input>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button plain icon="document" :data-query="JSON.stringify(tableFormatData.userTable.files)" v-exceldown="{path:'getBusinessSettlement&',query: {export: 1}}">{{ $t('excel.export') }}列表</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column width="5">
                </el-table-column>
                <el-table-column prop="date" label="商家ID" min-width="40">
                    <template slot-scope="scope">
                        <span>{{scope.row.id}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="商户">
                    <template slot-scope="scope">
                        <img class="logo" v-if="scope.row.logo" :src="scope.row.logo.file_path" alt="">
                        <span>{{scope.row.name}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" :render-header="renderHeaderOne" >
                    <template slot-scope="scope">
                        <p class="merchantLine">订单数量：{{scope.row.salesAmount}}</p>
                        <p class="merchantLine">金额：{{scope.row.salesVolume}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="商家入账">
                    <template slot-scope="scope">
                        <p class="merchantLine">入账数量：{{scope.row.numberEntries}}</p>
                        <p class="merchantLine">金额：{{scope.row.amountAccount}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="提现中">
                    <template slot-scope="scope">
                        <p class="merchantLine">入账数量：{{scope.row.applyIngMoney}}</p>
                        <p class="merchantLine">金额：{{scope.row.applyIngNum}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="已提现">
                    <template slot-scope="scope">
                        <p class="merchantLine">入账数量：{{scope.row.applyEdMoney}}</p>
                        <p class="merchantLine">金额：{{scope.row.applyEdNum}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="分销数据">
                    <template slot-scope="scope">
                        <p class="merchantLine">订单数量：{{scope.row.dealerTotalNum}}</p>
                        <p class="merchantLine">金额：{{scope.row.dealerTotalMoney}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="累计退款">
                    <template slot-scope="scope">
                        <!-- <p class="merchantLine">订单数量：{{scope.row.totalNum}}</p> -->
                        <p class="merchantLine">{{scope.row.totalRefundMoney.toFixed(2)}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="商家可结算金额">
                    <template slot-scope="scope">
                        <span>{{scope.row.yuE.toFixed(2)}}</span>
                    </template>
                </el-table-column>
                 <el-table-column prop="date" label="商家可提现余额">
                    <template slot-scope="scope">
                        <span>{{scope.row.bus_balance}}</span>
                    </template>
                </el-table-column>
                <!-- <el-table-column :render-header="renderHeaderOne">
                    <template slot-scope="scope">
                        <span>{{scope.row.numberEntries}}</span>
                    </template>
                </el-table-column>
                <el-table-column :render-header="renderHeaderOne">
                    <template slot-scope="scope">
                        <span>{{scope.row.amountAccount}}</span>
                    </template>
                </el-table-column> -->
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <router-link class="wlm-text" tag="a" target="_blank" :to="{path:'/merchant/merchantSettlementBill', query:{
                                id:scope.row.id,
                                store_user_id:$route.query.store_user_id?$route.query.store_user_id:'',
                  h_aid:$route.query.h_aid?$route.query.h_aid:'',}}">
                                <el-button type="text">入账账单</el-button>
                            </router-link>
                            <el-tooltip class="item" effect="dark" content="标记" placement="top">
                                <span @click="openDialog(scope.row.admin_remark.color,scope.row.admin_remark.remark,scope.row.id)">
                                    <svg-icon icon-class="qisan" :class="['qi-svg',scope.row.admin_remark.color]" />
                                </span>
                            </el-tooltip>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <el-row class="pagination-btns">
                    <!-- <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button> -->
                </el-row>
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  getBusinessSettlement,
  addBackstageRemark
} from '@/api/merchant'
import exceldown from '@/directive/exceldown'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'MerchantSettlement',
  components: {
  },
  directives: {
    exceldown
  },
  data() {
    return {
      moniForm: {},
      dialogVisibleImg: false,
      historyColor: 'red',
      historyRemark: '',
      historyId: '',
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: getBusinessSettlement
            //   delList: userListDel,
          },
          tableData: [],
          files: {
            name: '',
            ids: [],
            checkall: '0',
            Recycle: '1'
          },
          //   change: {
          //     restore: {
          //       name: '恢复',
          //       key: 'restore',
          //       api: userRestore
          //     }
          //   },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    openDialog(color, remark, id) {
      console.log(color, remark, id)
      color === undefined ? this.historyColor = 'red' : this.historyColor = color
      this.historyRemark = remark
      this.historyId = id
      this.dialogVisibleImg = true
    },
    clearData() {
      this.historyColor = ''
      this.historyRemark = ''
      this.historyId = ''
    },
    saveDialog() {
      addBackstageRemark({ id: this.historyId, color: this.historyColor, remark: this.historyRemark, key: 'business_settlement' }).then((response) => {
        const {
          data: {
            code: msgData = []
          }
        } = response
        if (msgData === 1) {
          this.$message.success('操作成功！')
          this.dialogVisibleImg = false
          this.filesSerch()
        }
      })
    },
    renderHeaderOne(h, { column, $index }) {
      const label = {
        3: '平台销售',
        5: '入账金额'
      }
      const contentText = {
        3: '包含已退款金额，不包含串码订单数据',
        5: '销售金额-分销佣金-退款金额'
      }
      return h('el-popover',
        { props: { placement: 'top', width: '200', trigger: 'hover', content: contentText[$index] } },
        [ // 父节点p，数组装子节点，第一个都是标签名字
          h('el-button', {// 第二个子节点，样式写在style，class名字写在calss上
            slot: 'reference', // slot 名字跟上面一样写
            props: {
              type: 'text'
            },
            style: {
              color: 'rgb(144, 147, 153)',
              fontWeight: '700'
            }
          },
          [
            label[$index], // 第一个节点，是一个跟着变的文字，没有属性
            h('i', {
              class: 'el-icon-question',
              style: { marginLeft: '5px' }
            })// 第二个节点，是i标签icon，设置属性
          ])
        ])
    }
  }
}
</script>

<style lang="scss" scoped>
.merchant-settlement {
    .qi-svg {
        font-size: 15px;
        fill: #ccc;
        cursor: pointer;
    }
    .merchantLine{
        line-height: 38px;
    }
    .qi-svg.red {
        fill: rgb(245, 108, 108);
    }

    .qi-svg.yellow {
        fill: rgb(250, 212, 0);
    }

    .qi-svg.green {
        fill: rgb(104, 211, 135);
    }

    .qi-svg.blue {
        fill: rgb(64, 158, 255);
    }

    .qi-svg.purple {
        fill: rgb(199, 21, 133);
    }
}
</style>
